﻿namespace TG.Timer
{
    public class TimerManager
    {
        private static TimerManager instance;

        public static TimerManager Instance => instance ??= new TimerManager();

        public delegate void TimerCallBack();

        /// <summary>
        /// 每帧计时器
        /// </summary>
        public event TimerCallBack FrameElapsed;

        /// <summary>
        /// 秒计时器
        /// </summary>
        public event TimerCallBack SecondsElapsed;

        /// <summary>
        /// 帧计时器添加
        /// </summary>
        /// <param name="callBack"></param>
        public void AddFrameElapsed(TimerCallBack callBack)
        {
            FrameElapsed += callBack;
        }
        
        public void SubFrameElapsed(TimerCallBack callBack)
        {
            FrameElapsed -= callBack;
        }
        
        /// <summary>
        /// 秒计时器添加
        /// </summary>
        /// <param name="callBack"></param>
        public void AddSecondsElapsed(TimerCallBack callBack)
        {
            SecondsElapsed += callBack;
        }

        public void SubSecondsElapsed(TimerCallBack callBack)
        {
            SecondsElapsed += callBack;
        }
        
        public void OnFrameElapsed()
        {
            FrameElapsed?.Invoke();
        }

        public void OnSecondsElapsed()
        {
            SecondsElapsed?.Invoke();
        }
    }
}